import {defineStore} from 'pinia';

const statusOption = [
    {label: "正常", value: "1"},
    {label: "停用", value: "-1"}
]

const API = {
    LIST: '',
}

const COLUMNS = [
    {field: "demo", title: "字典编码", align: "center", width: "150px"},
    {field: "demo", title: "字典标签", align: "center", width: "150px"},
    {field: "demo", title: "字典键值", align: "center", width: "150px"},
    {field: "demo", title: "字典排序", align: "center", width: "150px"},
    {field: "demo", title: "状态", align: "center", width: "150px"},
    {field: "demo", title: "备注", align: "center", width: "150px"},
    {field: "demo", title: "创建时间", align: "center"},
]

const SEARCH_FORM = [
    {field: "demo", title: "字典名称", options: []},
    {field: "demo", title: "字典标签", placeholder: "请输入字典标签"},
    {field: "demo", title: "状态", options: statusOption},
]

const OPTIONS = [
    {emit: "modify", title: "修改"},
    {emit: "remove", title: "删除"},
]

const store = {
    id: "dictData",
    state(){
        return {
            table: null,
            pageNo: 1,
            pageSize: 10,
            searchForm: {}
        }
    },

    getters: {

    },

    actions: {
        init(table) {
            this.table = table;
            this.table.setColumns(COLUMNS);
            this.table.setSearchForm(SEARCH_FORM);
            this.table.setOptions(OPTIONS);
        },

        refresh(isFirstPage) {
            if (isFirstPage) {
                this.getList(1, 10)
                return
            }
            this.getList(this.pageNo, this.pageSize)
        },

        /**
         * 列表数据
         * @param pageNo
         * @param pageSize
         * @param condition
         * @returns {Promise<void>}
         */
        async getList(pageNo, pageSize, condition) {
            let params = {};
            params.current = pageNo ? pageNo : 1;
            params.size = pageSize ? pageSize : 10;
            for (let key in condition) {
                if(! Helper.empty(condition[key])) {
                    params[key] = condition[key];
                }
            }

            // Msg.loading("加载中...")
            // let {data} = await Http.post(API.LIST, params);
            // Msg.loading(false)
            //
            // this.pageNo = data.current
            // this.pageSize = data.size
            // let dataList = []
            // if(! Helper.emptyArray(data.records)) {
            //     dataList = data.records
            // }
            // this.table.setData(dataList);
            // this.table.setPagination(data.current, data.size, data.total);

            this.table.setData([{demo: "测试"}])
            this.table.setPagination(1, 10, 30);
        },
    },
}

export default defineStore(store)